<!DOCTYPE html>
<html>
<head>
    <title>Energy Level Diagram</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        canvas {
            border: 1px solid #ccc;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <canvas id="physicsCanvas" width="600" height="400"></canvas>
    <script>
        const canvas = document.getElementById('physicsCanvas');
        const ctx = canvas.getContext('2d');

        // Style settings
        ctx.strokeStyle = 'black';
        ctx.fillStyle = 'black';
        ctx.lineWidth = 3;
        ctx.lineCap = 'butt'; // For sharp line ends

        // --- Draw the outer rectangle ---
        ctx.strokeRect(50, 50, 500, 250);

        // --- Draw the n=2 level ---
        const y_n2 = 110;
        ctx.font = "bold 28px 'Courier New', monospace";
        ctx.textAlign = 'left';
        ctx.textBaseline = 'middle';
        ctx.fillText("n = 2", 80, y_n2);

        // Draw the three horizontal lines for n=2
        ctx.beginPath();
        ctx.moveTo(200, y_n2);
        ctx.lineTo(300, y_n2);
        ctx.stroke();

        ctx.beginPath();
        ctx.moveTo(330, y_n2);
        ctx.lineTo(430, y_n2);
        ctx.stroke();
        
        ctx.beginPath();
        ctx.moveTo(460, y_n2);
        ctx.lineTo(560, y_n2);
        // Correcting line to stay within the box
        ctx.clearRect(550, y_n2-5, 10, 10); // Clear any overflow
        ctx.beginPath();
        ctx.moveTo(460, y_n2);
        ctx.lineTo(540, y_n2);
        ctx.stroke();


        // --- Draw the n=1 level ---
        const y_n1 = 250;
        // Font is already set
        ctx.fillText("n = 1", 80, y_n1);

        // Draw the horizontal line for n=1
        ctx.beginPath();
        ctx.moveTo(200, y_n1);
        ctx.lineTo(320, y_n1);
        ctx.stroke();

        // --- Draw the Figure Caption ---
        ctx.font = "24px 'Times New Roman', serif";
        ctx.textAlign = 'center';
        ctx.textBaseline = 'bottom';
        ctx.fillText("Fig. 1.14", canvas.width / 2, 350);

    </script>
</body>
</html>